﻿using System.Web;
using System.Web.SessionState;

using Gonte.Data.DataService;
using System;

namespace Gonte.Desktop.Web
{
    public class SessionHelper
    {
        public static IDataService DataService 
        { 
            get
            {
                return (IDataService)HttpContext.Current.Session["DataService"];
            }

            set
            {
                HttpContext.Current.Session["DataService"] = value;
            }
        }

        public static ApplicationUser ApplicationUser
        {
            get
            {
                return (ApplicationUser)HttpContext.Current.Session["ApplicationUser"];
            }

            set
            {
                HttpContext.Current.Session["ApplicationUser"] = value;
            }
        }

        public static Func<Tuple<bool, string>> SessionVerifier = () =>
        {
            ApplicationUser user = ApplicationUser;

            if (user == null)
            {
                return new Tuple<bool, string>(false, "Session expired");
            }

            return new Tuple<bool, string>(true, string.Empty);
        };
    }
}